package com.java.demo.model;

/**
 * 适配器模式
 *
 * @auther zhangwj
 * @date 2020/12/3 下午2:30
 */
public class AdapterPattern {

    public static void main(String[] args) {
        V220 v220 = new V220Impl();
        Adapter adapterV22 = new Adapter(v220);
        adapterV22.outV110();

        V110 v110 = new V110Impl();
        Adapter adapterV11 = new Adapter(v110);
        adapterV11.outV220();
    }
}

class Adapter implements V110, V220 {

    private V220 v220;

    private V110 v110;

    public Adapter(V220 v220) {
        this.v220 = v220;
    }

    public Adapter(V110 v110) {
        this.v110 = v110;
    }

    @Override
    public void outV110() {
        System.out.println("V110通过加压操作后");
        v220.outV220();
    }

    @Override
    public void outV220() {
        System.out.println("V220通过减压操作后");
        v110.outV110();
    }
}


interface V110 {
    void outV110();
}

class V110Impl implements V110 {

    @Override
    public void outV110() {
        System.out.println("输出电压110度");
    }
}

interface V220 {
    void outV220();
}

class V220Impl implements V220 {

    @Override
    public void outV220() {
        System.out.println("输出电压220度");
    }
}